package com.moss.system.service.impl;

import com.moss.common.entity.SysCheckEntity;
import com.moss.common.entity.SysSampleEntity;
import com.moss.common.vo.check.SysCheck;
import com.moss.system.mapper.CheckItemMapper;
import com.moss.system.mapper.CheckMapper;
import com.moss.system.mapper.SampleMapper;
import com.moss.system.service.CheckService;
import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Transactional;

import javax.annotation.Resource;
import java.util.List;

@Service
public class CheckServiceImpl implements CheckService {

    @Resource
    CheckMapper checkMapper;

    @Resource
    CheckItemMapper checkItemMapper;

    @Resource
    SampleMapper sampleMapper;


    @Override
    @Transactional(rollbackFor = Exception.class)
    public void saveCheck(SysCheckEntity check) {
        checkMapper.insert(check);
        checkItemMapper.insert(check.getItemList());
        SysSampleEntity sample = new SysSampleEntity();
        sample.setSampleId(check.getSampleId());
        sample.setStatus(1);
        sample.setUpdateBy(check.getCreateBy());
        sampleMapper.updateById(sample);
    }

    @Override
    public SysCheckEntity getCheck(String sampleId) {
        SysCheckEntity check = checkMapper.selectById(sampleId);
        check.setItemList(checkItemMapper.selectById(sampleId));
        return check;
    }


    @Override
    public List<SysCheck> checkList(SysCheckEntity check) {
        return checkMapper.selectList(check);
    }
}
